package com.project.service.impl;

import com.project.bean.StudentBean;
import com.project.mapper.IStudentDao;
import com.project.service.IStudentService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 学生业务实现类
 */
public class StudentServiceImpl extends BaseService implements IStudentService {


    @Override
    public void studentInRoom(StudentBean student) {
        SqlSession session = this.getSession();
        IStudentDao studentDao = session.getMapper(IStudentDao.class);
        studentDao.studentInRoom(student);
        session.commit();
        session.close();
    }

    @Override
    public void delStudentInfo(Integer id) {
        SqlSession session = this.getSession();
        IStudentDao studentDao = session.getMapper(IStudentDao.class);
        studentDao.delStudentInfo(id);

        session.commit();
        session.close();
    }

    @Override
    public void updateStudentRoom(Integer studentId, Integer roomId) {
        SqlSession session = this.getSession();
        IStudentDao studentDao = session.getMapper(IStudentDao.class);
        studentDao.updateStudentRoom(studentId,roomId);

        session.commit();
        session.close();
    }

    @Override
    public StudentBean findById(Integer id) {
        SqlSession session = this.getSession();
        IStudentDao studentDao = session.getMapper(IStudentDao.class);
        StudentBean studentBean = studentDao.findById(id);

        session.close();
        return studentBean;
    }

    @Override
    public List<StudentBean> findByItem(String name, String className, String roomAddress) {
        SqlSession session = this.getSession();
        IStudentDao studentDao = session.getMapper(IStudentDao.class);
        List<StudentBean> list = studentDao.findByItem(name,className,roomAddress);
        session.close();
        return list;
    }
}
